<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="./three.min.js"></script>
    <script src="./CSS3DRenderer.js"></script>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        html,
        body {
            width: 100%;
            height: 100%;
        }
    </style>
</head>

<body>

    <script>
        let opt = {
            width: window.innerWidth,
            height: window.innerHeight,
            fov: 75,
            radius: 50,
            url: 'https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimg8.zol.com.cn%2Fbbs%2Fupload%2F18674%2F18673802.jpg&refer=http%3A%2F%2Fimg8.zol.com.cn&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1624579101&t=8ba1786dcc6bebda832ce7bf3c8db89a',
            container: document.body
        }
        let camera = new THREE.PerspectiveCamera(opt.fov, opt.width / opt.height, 1, 10000);
        camera.target = new THREE.Vector3(0, 0, 0);
        // 球体
        var geometry = new THREE.SphereBufferGeometry(opt.radius, 60, 60);
        geometry.scale(-1, 1, 1);
        // 材质
        var material = new THREE.MeshBasicMaterial({
            map: new THREE.TextureLoader().load(opt.url)
        });
        // 场景
        var mesh = new THREE.Mesh(geometry, material);
        scene = new THREE.Scene();
        scene.background = new THREE.Color(0xf0f0f0);
        scene.add(mesh);

        // 渲染
        renderer = new THREE.WebGLRenderer();
        renderer.setPixelRatio(window.devicePixelRatio);
        renderer.setSize(opt.width, opt.height);
        canvas = renderer.domElement;
        opt.container.appendChild(canvas);

        // 监听
        window.addEventListener('touchstart', start);
        window.addEventListener('touchmove', move);
        window.addEventListener('touchend', end);

        // 开始触摸
        function start(event) {
            var evt = event.changedTouches[0];
            startX = evt.clientX;
            lastX = evt.clientX;
            startY = evt.clientY;
            lastY = evt.clientY;
        }

        // 滑动
        function move(event) {
            var evt = event.changedTouches[0];
            switch (event.changedTouches.length) {
                case 1:
                    lon += (evt.clientX - lastX) * factor;
                    lat += (evt.clientY - lastY) * factor;

                    lastX = evt.clientX;
                    lastY = evt.clientY;
                    break;
                case 2:
                    // 如果要做放大缩小效果的话，可以在这里补充，我偷懒没写这种情况╮(╯▽╰)╭    }
            }
        }
            // 结束
            function end(event) {
                // 这里可以添加减速效果增加流畅性，没错我又偷懒了
            }
    </script>
</body>

</html>